package com.zhuangjie.order.service.impl;

import com.zhuangjie.mvc.sse.entity.SSEResult;
import com.zhuangjie.mvc.sse.service.AbstractSSEService;
import com.zhuangjie.order.entity.Order;
import com.zhuangjie.order.enums.ShopSSEMessageType;
import com.zhuangjie.order.service.ShopSSEService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ShopSSEServiceImpl extends AbstractSSEService<Long> implements ShopSSEService {
    @Override
    public void newOrderArrived(Order order)  {
        try {
            SSEResult sseResult = new SSEResult();
            sseResult.setData(order);
            sseResult.setMessageType(ShopSSEMessageType.NEW_ORDER_ARRIVED);
            send(order.getShopId(), sseResult);
        }catch (Exception e) {
            log.error("发送新订单通知失败！订单号:"+order.getOrderNo());
        }
    }

}
